<?php

namespace app\weixin\controller;

class Order extends Base
{
    /**
     * 订单列表
     * @return type
     */
    public function index(){
        $map = [];
        $add_time = input("add_time");//搜索条件
        $pay_time = input("pay_time");
        $user_name = input("user_name");
        $order_sn = input("order_sn");
        if(!empty($add_time)){
            $a= strtotime($add_time);
            $start_a = mktime(0,0,0,date("m",$a),date("d",$a),date("Y",$a));
            $end_a = mktime(23,59,59,date("m",$a),date("d",$a),date("Y",$a));
            $map['add_time']=array(array('egt',$start_a),array('elt',$end_a),'and');
        }
        if(!empty($pay_time)){
            $p= strtotime($pay_time);
            $start_p = mktime(0,0,0,date("m",$p),date("d",$p),date("Y",$p));
            $end_p = mktime(23,59,59,date("m",$p),date("d",$p),date("Y",$p));
            $map['pay_time']=array(array('egt',$start_p),array('elt',$end_p),'and');
        }
        if(!empty($user_name)){
            $map["user_name"] = [
                'like',
                "%$user_name%" 
            ];
        }
        if(!empty($order_sn)){
            $map["order_sn"] = [
                'like',
                "%$order_sn%" 
            ];
        }
        $pagesize = config('paginate')['list_rows'];//每页数量
        $param=request()->param(); //获取url参数
        $lists = db('order_info')->where($map)->order('order_id desc')->paginate($pagesize,false,array('query' => array_splice($param,1)));
        $this->assign("lists",$lists);
        $this->assign("page", $lists->render());
        return $this->fetch();
    }
    
     /**
      * 删除订单
      * @return type
      */
    public function del_order(){
        $id = input('id');
        $res = db('order_info')->where(['order_id'=>$id])->delete();
        return $this->success('操作成功');
    }

}
